﻿mini.parse();
mini.getbyName("Gender").setValue("1");
mini.getbyName("Role").setValue("0");
var form = new mini.Form("form1");
var action;
function SaveData() {
    var o = form.getData();
    var json = mini.encode([o]);
    form.validate();
    if (form.isValid() == false) return;
    if (action == "new") {
        $.ajax({
            url: "../Service/SystemManageHandler.ashx?action=AddUser",
            data: { data: json },
            type: 'POST',
            success: function(text) {
                CloseWindow("save");
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }
}
function SetData(data) {
    if (data.action == "new") {
        data = mini.clone(data);
        action = data.action;
    }
}
function onUserNameChanged(e) {
    if (e.value) {
        $.ajax({
            url: "../service/SystemManageHandler.ashx?action=CheckedCode&tableName=dt_User&fieldName=UserName&Code=" + e.value,
            success: function(text) {
                if (text > 0) {
                    mini.alert(e.value + "已经存在！请重新输入！");
                    mini.getbyName("UserName").setValue("");
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }
}
function onIDNOValidation(e) {
    if (e.isValid) {
        var pattern = /\d*/;
        if (e.value.length < 15 || e.value.length > 18 || pattern.test(e.value) == false) {
            e.errorText = "必须输入15~18位数字";
            e.isValid = false;
        }
    }
}
function onPhoneValidation(e) {
    var reg = /^0{0,1}(13[4-9]|15[6-9]|15[0-2]|18[7-8])[0-9]{8}$/;
    if (!reg.test(e.value)) {
        e.errorText = "手机号码格式有误，请重新输入";
        e.isValid = false;
    }
}
function onQQValidation(e) {
    var reg = /^[1-9]\d{4-8}$/;
    if (!reg.test(e.value)) {
        e.errorText = "QQ号码格式有误，请重新输入";
        e.isValid = false;
    }
}
function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
        if (confirm("数据被修改了，是否先保存？")) {
            return false;
        }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
}

function onOk(e) {
    SaveData();
}
function onCancel(e) {
    CloseWindow("cancel");
}
function onPwdValidation(e) {
    if (e.isValid) {
        if (e.value.length < 3) {
            e.errorText = "密码不能少于3个字符";
            e.isValid = false;
        }
    }
}